<template>
  <div class="banner">
    <el-row>
      <el-col :span="18">
        <img class="logo" src="../assets/logo_icon.jpg" alt="">
        
      </el-col>
      <el-col :span="3">
        <el-avatar style="    position: fixed;
          border-radius: 50%;
          right: 13%; "  > {{userStore.username.charAt(0)}} </el-avatar>
      </el-col>
      
      
        
      <el-col :span="3">
      <div class="dropdown-wrapper">

        

        <el-dropdown>
          
          
      <el-button>
      欢迎，{{userStore.username}}<el-icon class="el-icon--right"><arrow-down /></el-icon>
      </el-button>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item  @click="usermessage">个人中心</el-dropdown-item>
          <el-dropdown-item @click="loginout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
      </div>
      </el-col>
    </el-row>
  </div>
  <div class="wrapper">
    <Menu class="left" />
    <div class="right">
      <router-view></router-view>
    </div>
  </div>
</template>

<script setup>
import { UserFilled } from '@element-plus/icons-vue'
import Menu from "../components/admin/Menu.vue";
import { useTokenStore } from '../store/token';
import { useUserStore } from '../store/user';
import { onMounted } from "vue";
import api from "../helper/api";
import {ArrowDown} from '@element-plus/icons-vue'
import {useRouter} from 'vue-router';

import {ref} from 'vue';

const router = useRouter();
let loginout = () => {
  const tokenStore =  useTokenStore();
  tokenStore.setToken("");
  router.push("/login");
};
// 个人中心
let usermessage = () => {
  // const tokenStore =  useTokenStore();
  // tokenStore.setToken("");
  router.push("/My");
};


const  userInfo = ref({});
const tokenStore = useTokenStore();
const userStore = useUserStore();
api.getUserDetail(`${userStore.username}`).then((res) => {
    let user = res.data["data"];
    userStore.setUser(user.username, user.nickname, user.id);
});
onMounted(() => {

  // 获取用户信息
  userInfo.value = {
    username:userStore.username,
    nickname:userStore.nickname,
    id:userStore.id
  }

});
</script>

<style scoped>
.banner {
  height: 40px;
  line-height: 40px;
  box-sizing: border-box;
}
.el-menu {
  height: calc(100vh - 40px);
}
.wrapper {
  display: flex;
  background-color: #eef1f5;
}

.right {
  width: 100%;
  height: calc(100vh - 40px);
}
.el-col {
  /* border: 1px solid red; */
}
.dropdown-wrapper{
  padding: 5px;
  text-align: center;
}
.logo{
  zoom:0.75;
  margin-left: 20px;
}
</style>
